<?php

class PhpFox_Mod_Smiles_ComponentEmoticons extends BaseComponent
{
	function process()
	{
		$oCache =& App::getCache();
		$sTextId = $this->getParam('textid');

	$oCache->setFile('emoticons.php');
	if ( !$oCache->isCached() )
	{
    	$sDir = opendir(App::getParam('smile.path') . 'emo/');
    	$aEmo = array();
    	while ($sFile = readdir($sDir))
		{
			if (ereg("jpg",$sFile) || ereg("gif",$sFile))
			{
				$aEmo[] = $sFile;
			}
		}
		$oCache->save($aEmo);
    }

    $aEmoticons = $oCache->doRequire();


	$sEmotions = '
	<div style="position:relative;">
	<div style="position:absolute;">
	<div id="emoticons-inner" style="overflow:auto; width:300px; height:120px;" class="border2">
	<table style="width:90%;" cellpadding="0" cellspacing="0">
	<tr>
	';

	foreach( $aEmoticons as $iId => $sFile )
	{
		$sEmo = str_replace(".jpg","", $sFile);
    	$sEmo = str_replace(".gif","", $sEmo);
		$sEmotions .= '
		<td style="text-align:center;">
			<a href="javascript:void(0);" onclick="insertAtCursor(document.getElementById(\''. $sTextId .'\'), \':'.$sEmo.':\', 4); document.getElementById(\'emoticons-outer\').style.display=\'none\';">
			<img src="'. App::getParam('smile.url') .'emo/'.$sFile.'" style="vertical-align:middle;" alt="" />
			</a>
		</td>
		'. (is_int(($iId+1)/3) ? '</tr><tr>' : '') .'';
	}

	$sEmotions .= '
	</tr>
	</table>
	</div>
	<div class="border2" style="text-align:right; padding:2px; border-top:none;">
		<a href="javascript:void(0);" onclick="document.getElementById(\'emoticons-outer\').style.display=\'none\';">' . App::format('close') . '</a>
	</div>
	</div></div>';

		return $sEmotions;
	}
}
?>
